package cn.lizemin.demo.thread;

/**
 * @author: lizemin
 * @version: 1.0
 * 使用方法一：
 * 1.自定义一个类继承thread类
 * 2.run方法中放新的线程要执行的代码
 */
public class ThreadDemo{
    //这是一个main方法,是程序的入口
    public static void main(String[] args) throws InterruptedException {
        System.out.println("main线程已开启");
        MyRunnable myRunnable = new MyRunnable();
        //创建线程对象
        Thread thread = new Thread(myRunnable,"小强");
        Thread thread2 = new Thread(myRunnable,"旺财");
        MyThread thread3 = new MyThread("好奇号线程");
        //创建线程对象后，查看线程状态:new
        System.out.println("thread当前的线程状态为:"+thread2.getState());
        //开启线程
        thread.start();
        thread2.start();
        thread3.start();
        //开启线程后，查看线程状态:runnable
        System.out.println("thread当前的线程状态为:"+thread2.getState());
        Thread.sleep(500);
        //线程沉睡后，查看线程状态:TERMINATED
        System.out.println("thread当前的线程状态为:"+thread2.getState());


    }
}
